//
//  XWUserModel.swift
//  XiaoweHealthy
//
//  Created by Riven on 2022/3/24.
//

import Foundation

enum XWUserGenderType: Int {
    
    case none = -1
    case female = 0
    case male
    
    var name: String {
        switch self {
        case .none:
            return "未知"
            
        case .female:
            return "女"
            
        case .male:
            return "男"
        }
    }
    
}

class XWUserModel: XWDataBaseModel {
    
    /// 手机号码
    var phone = ""
    
    /// 邮箱
    var email = ""
    
    /// 真实姓名
    var realName = ""
    
    /// 昵称
    var nickname = ""
    
    /// 用户编码
    var userCode = ""
    
    /// 头像
    var avatar = ""
    
    /// 性别 0 女 1 男
    var gender: Int = -1
    
    var genderType: XWUserGenderType {
        return XWUserGenderType(rawValue: gender) ?? .none
    }
    
    /// 身高 cm
    var height: Double = 170
    
    /// 体重
    var weight: Double = 60
    
    /// 生日 格式yyyy-MM-dd
    var birthday: String = ""
    
    /// 年龄
    var age: Int {
        let cDate = Date()
        guard let bDate = birthday.date(withFormat: "yyyy-MM-dd") else {
            return 0
        }
    
        return cDate.year - bDate.year
    }
    
    var store = ""
    var storeId = 0
    
    /// 是否设置了密码 true已设置密码，false未设置密码
    var hasPassword: Bool = false
    
    // 对应菜单权限
    var privileges = XWAccountUserFunctionModel()
    
    override var description: String {
        return "{ uniqueId = \(uniqueId), phone = \(phone), email = \(email), nickname = \(nickname), gender = \(gender), height = \(height), height = \(weight), birthday = \(birthday), avatar = \(avatar) }"
    }
    
    override func mapping(mapper: HelpingMapper) {
        mapper <<<
            realName <-- "name"
    }
    
}
